package cn.qihang.ssm.controller;

import cn.qihang.ssm.pojo.Book;
import cn.qihang.ssm.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: qihang
 * @Date: 2022/10/31 11:34
 * @Desc:
 */
@Controller
@RequestMapping("book")
public class BookController {
    @Autowired
    private BookService bookService;

    /**
     *  页面显示
     * @return
     */
    @RequestMapping("findAllpage")
    public String findAllBooks(Model model){
        List<Book> list = this.bookService.findAllBooks();
        model.addAttribute("books",list);
        return "books";

    }

    /**
     *  响应json
     * @return
     */
    @RequestMapping("findAll")
    @ResponseBody
    public List<Book> findAllBooks(){
        return this.bookService.findAllBooks();
    }
}

